package com.api.shopapi.mapper;

import com.api.shopapi.entity.ActivityType;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface ActivityTypeMapper {


    @Insert("insert into activity_type " +
            "(" +
            "ActivityTypeCode," +
            "GovernmentCode," +
            "CommandCenterCode," +
            "Name," +
            "Status," +
            "Sort" +
            ") " +
            "values " +
            "(" +
            "#{activityType.ActivityTypeCode}," +
            "#{activityType.GovernmentCode}," +
            "#{activityType.CommandCenterCode}," +
            "#{activityType.Name}," +
            "#{activityType.Status}," +
            "#{activityType.Sort}" +
            ")" )
    int insert(@Param("activityType") ActivityType activityType);


    @Delete("delete from activity_type where activityTypeCode=#{activityTypeCode}")
    int delete(@Param("activityTypeCode") String activityTypeCode);


    @Update("update activity_type set " +
            " Name=#{activityType.Name}," +
            " Status=#{activityType.Status}," +
            " GovernmentCode=#{activityType.GovernmentCode}," +
            " CommandCenterCode=#{activityType.CommandCenterCode}," +
            " Sort=#{activityType.Sort}" +
            " where activityTypeCode=#{activityType.activityTypeCode}")
    int update(@Param("activityType") ActivityType activityType);


    @Select("select * from activity_type where activityTypeCode=#{activityTypeCode} limit 1")
    ActivityType getByActivityTypeCode(@Param("activityTypeCode") String activityTypeCode);


    @Select("select * from activity_type where commandCenterCode=#{commandCenterCode}" +
            " order by Sort desc")
    List<ActivityType> listByCommandCenterCode(@Param("commandCenterCode") String commandCenterCode);

}
